<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8"/>    <title>littleTwo商城后台</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <link href="http://127.0.0.1/PHP/MyShop/littleTwoShop/resource/hdjs/css/bootstrap.min.css" rel="stylesheet">
    <link href="http://127.0.0.1/PHP/MyShop/littleTwoShop/resource/css/site.css" rel="stylesheet">
    <link href="http://127.0.0.1/PHP/MyShop/littleTwoShop/resource/hdjs/css/font-awesome.min.css" rel="stylesheet">
    <script src="http://127.0.0.1/PHP/MyShop/littleTwoShop/resource/hdjs/js/jquery.min.js"></script>
    <script src="http://127.0.0.1/PHP/MyShop/littleTwoShop/resource/hdjs/app/util.js"></script>
    <script src="http://127.0.0.1/PHP/MyShop/littleTwoShop/resource/hdjs/require.js"></script>
    <script src="http://127.0.0.1/PHP/MyShop/littleTwoShop/resource/hdjs/app/config.js"></script>
    <!--[if lt IE 9]>
    <script src="http://cdn.bootcss.com/html5shiv/r29/html5.min.js"></script>
    <script src="http://cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
    <script>
        if (navigator.appName == 'Microsoft Internet Explorer') {
            if (navigator.userAgent.indexOf("MSIE 5.0") > 0 || navigator.userAgent.indexOf("MSIE 6.0") > 0 || navigator.userAgent.indexOf("MSIE 7.0") > 0) {
                alert('您使用的 IE 浏览器版本过低, 推荐使用 Chrome 浏览器或 IE8 及以上版本浏览器.');
            }
        }
    </script>
    <style>
        i {
            color: #337ab7;
        }
    </style>
</head>
<body>
<div class="container-fluid admin-top">
    <!--导航-->
    <nav class="navbar navbar-inverse">
        <div class="container-fluid">
            <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                <h4 style="display: inline;line-height: 50px;float: left;margin: 0px"><a href="" style="color: white;margin-left: -14px">littleTwo商城后台</a></h4>
                <div class="navbar-header">
                    <ul class="nav navbar-nav">

                        <li>
                            <a href="http://doc.hdphp.com" target="_blank"><i class="fa fa-w fa-file-code-o"></i> 在线文档</a>
                        </li>
                        <li>
                            <a href="http://fontawesome.dashgame.com/" target="_blank"><i class="fa fa-w fa-hand-o-right"></i>   图标库</a>
                        </li>
                        <li>
                            <a href="http://bbs.houdunwang.com" target="_blank"><i class="fa fa-w fa-forumbee"></i> 论坛讨论</a>
                        </li>
                    </ul>
                </div>
                <ul class="nav navbar-nav navbar-right">
                    <li class="dropdown">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button">
                            <i class="fa fa-w fa-user"></i>
                            anct                            <span class="caret"></span>
                        </a>
                        <ul class="dropdown-menu">
                            <li><a href="http://127.0.0.1/PHP/MyShop/littleTwoShop/index.php?s=admin/Index/changePass">修改密码</a></li>
                            <li role="separator" class="divider"></li>
                            <li><a href="http://127.0.0.1/PHP/MyShop/littleTwoShop/index.php?s=admin/Login/out">退出</a></li>
                        </ul>
                    </li>
                </ul>
            </div>
        </div>
    </nav>
    <!--导航end-->
</div>
<!--主体-->
<div class="container-fluid admin_menu">
    <div class="row">
        <div class="col-xs-12 col-sm-3 col-lg-2 left-menu">
            <div class="panel panel-default" id="menus" >
                <!--商品分类管理-->
                <div class="panel-heading" role="button" data-toggle="collapse" href="#collapseExample" aria-expanded="false" aria-controls="collapseExample" style="border-top: 1px solid #ddd;border-radius: 0%">
                    <h4 class="panel-title">分类管理</h4>
                    <a class="panel-collapse" data-toggle="collapse" href="#collapseExample" aria-expanded="true">
                        <i class="fa fa-chevron-circle-down"></i>
                    </a>
                </div>
                <ul class="list-group menus collapse in" id="collapseExample">
                    <a href="http://127.0.0.1/PHP/MyShop/littleTwoShop/index.php?s=admin/Category/index" class="list-group-item" >
                        <i class="fa fa-bar-chart" aria-hidden="true"></i>
                        <span class="pull-right" href=""></span>
                        分类列表
                    </a>
                    <a href="http://127.0.0.1/PHP/MyShop/littleTwoShop/index.php?s=admin/Category/add" class="list-group-item" >
                        <i class="fa fa-bars" aria-hidden="true"></i>
                        <span class="pull-right" href=""></span>
                        分类添加
                    </a>
                </ul>
                <!--
                                <!--商品分类管理菜单 end-->
                                <!--商品类型管理-->
                <div class="panel-heading" role="button" data-toggle="collapse" href="#collapseExample1" aria-expanded="false" aria-controls="collapseExample" style="border-top: 1px solid #ddd;border-radius: 0%">
                    <h4 class="panel-title">类型管理</h4>
                    <a class="panel-collapse" data-toggle="collapse" href="#collapseExample1" aria-expanded="true">
                        <i class="fa fa-chevron-circle-down"></i>
                    </a>
                </div>
                <ul class="list-group menus collapse in" id="collapseExample1">
                    <a href="http://127.0.0.1/PHP/MyShop/littleTwoShop/index.php?s=admin/Type/index" class="list-group-item" >
                        <i class="fa fa-bar-chart" aria-hidden="true"></i>
                        <span class="pull-right" href=""></span>
                        类型列表
                    </a>
                    <a href="http://127.0.0.1/PHP/MyShop/littleTwoShop/index.php?s=admin/Type/add" class="list-group-item" >
                        <i class="fa fa-bars" aria-hidden="true"></i>
                        <span class="pull-right" href=""></span>
                        类型添加
                    </a>
                </ul>
                <!--商品类型管理end-->
                <!--品牌管理菜单-->
                <div class="panel-heading" role="button" data-toggle="collapse" href="#collapseExample2" aria-expanded="false" aria-controls="collapseExample">
                    <h4 class="panel-title">品牌管理</h4>
                    <a class="panel-collapse" data-toggle="collapse" href="#collapseExample2" aria-expanded="true">
                        <i class="fa fa-chevron-circle-down"></i>
                    </a>
                </div>
                <ul class="list-group menus collapse in" id="collapseExample2">
                    <a href="http://127.0.0.1/PHP/MyShop/littleTwoShop/index.php?s=admin/brand/index" class="list-group-item" >
                        <i class="fa fa-bookmark" aria-hidden="true"></i>
                        <span class="pull-right" href=""></span>
                        品牌列表
                    </a>
                    <a href="http://127.0.0.1/PHP/MyShop/littleTwoShop/index.php?s=admin/brand/add" class="list-group-item" >
                        <i class="fa fa-caret-square-o-up" aria-hidden="true"></i>
                        <span class="pull-right" href=""></span>
                        品牌添加
                    </a>
                </ul>
                <!--品牌管理菜单 end-->
                <!--商品管理菜单-->
                <div class="panel-heading" role="button" data-toggle="collapse" href="#collapseExample3" aria-expanded="false" aria-controls="collapseExample">
                    <h4 class="panel-title">商品管理</h4>
                    <a class="panel-collapse" data-toggle="collapse" href="#collapseExample3" aria-expanded="true">
                        <i class="fa fa-chevron-circle-down"></i>
                    </a>
                </div>
                <ul class="list-group menus collapse in" id="collapseExample3">
                    <a href="http://127.0.0.1/PHP/MyShop/littleTwoShop/index.php?s=admin/goods/index" class="list-group-item" >
                        <i class="fa fa-book" aria-hidden="true"></i>
                        <span class="pull-right" href=""></span>
                        商品列表
                    </a>
                    <a href="http://127.0.0.1/PHP/MyShop/littleTwoShop/index.php?s=admin/goods/add" class="list-group-item" >
                        <i class="fa fa-clone" aria-hidden="true"></i>
                        <span class="pull-right" href=""></span>
                        商品添加
                    </a>

                </ul>
                <!--商品管理菜单end-->
                <!--网站配置管理菜单-->
                <div class="panel-heading" role="button" data-toggle="collapse" href="#collapseExample4" aria-expanded="false" aria-controls="collapseExample">
                    <h4 class="panel-title">网站配置</h4>
                    <a class="panel-collapse" data-toggle="collapse" href="#collapseExample4" aria-expanded="true">
                        <i class="fa fa-chevron-circle-down"></i>
                    </a>
                </div>
                <ul class="list-group menus collapse in" id="collapseExample4">
                    <a href="" class="list-group-item" >
                        <i class="fa fa-wrench" aria-hidden="true"></i>
                        <span class="pull-right" href=""></span>
                        站点配置
                    </a>
                </ul>
                <!--网站配置管理菜单 end-->
                <!--友情链接-->
                <div class="panel-heading" role="button" data-toggle="collapse" href="#collapseExample5" aria-expanded="false" aria-controls="collapseExample">
                    <h4 class="panel-title">友情链接</h4>
                    <a class="panel-collapse" data-toggle="collapse" href="#collapseExample5" aria-expanded="true">
                        <i class="fa fa-chevron-circle-down"></i>
                    </a>
                </div>
                <ul class="list-group menus collapse in" id="collapseExample5">
                    <a href="" class="list-group-item" >
                        <i class="fa fa-paper-plane" aria-hidden="true"></i>
                        <span class="pull-right" href=""></span>
                        链接列表
                    </a>
                    <a href="" class="list-group-item" >
                        <i class="fa fa-sign-in" aria-hidden="true"></i>
                        <span class="pull-right" href=""></span>
                        添加链接
                    </a>
                </ul>

                <!--友情链接end-->
            </div>
        </div>
        <div class="col-xs-12 col-sm-9 col-lg-10">
            
	<ul class="nav nav-tabs" role="tablist">
		<li><a href="<?php echo u('index')?>">商品管理</a></li>
		<li class="active"><a href="">商品修改</a></li>
	</ul>
	<form class="form-horizontal"  id="form" action="" method="post" onsubmit="return goodsEdit()">
		<div class="panel panel-default">
			<div class="panel-heading">
				<h3 class="panel-title">商品管理</h3>
			</div>
			<div class="panel-body">
				<div class="form-group">
					<label for="" class="col-sm-2 control-label">商品名称</label>
					<div class="col-sm-9">
						<input type="text" name="gname"  class="form-control" value="<?php echo $goodsdata['gname']?>" placeholder="请填写商品名称">
					</div>
				</div>
				<div class="form-group">
					<label for="" class="col-sm-2 control-label">所属分类</label>
					<div class="col-sm-9">
						<select class="js-example-basic-single form-control" name="cid">
							<option value="0">请选择分类</option>
							<?php foreach ((array)$catedata as $k=>$v){?>
								<option value="<?php echo $v['cid']?>" <?php if($goodsdata['cid']==$v['cid']){?>
                selected
               <?php }?> tid="<?php echo $v['tid']?>" ><?php echo $v['_cname']?></option>
							<?php }?>
						</select>
					</div>
				</div>
				<script>
					$(function(){
//						获取旧的属性规格值
						var oldattr=$('#attr').html();
						var oldspec=$('#spec').html();

						$('select[name=cid]').change(function(){
							//获取具有selected属性的元素
							var tid=$(':selected').attr('tid');
							var cid=$(this).val();
							//将tid写入隐藏域
							$('input[name=tid]').val(tid);
//							如果选择的cid与旧数据一样
							if(cid==<?php echo $goodsdata['cid']?>){
								$('#attr').html(oldattr);
								$('#spec').html(oldspec);
								return;
							}

							if(tid==0){
								alert('不能给顶级分类添加商品');
								$(this).val(0);
								return false;
							}
							$.post("<?php echo u('ajaxGetAttr')?>",{tid:tid},function(res){
								var attr='';/*属性*/
								var spec='';/*规格*/
								attr +='<table class="table table-striped">';
								spec +='<table class="table table-striped">';

								$.each(res,function(k,v){
									if(v.class==1){//说明是属性
										attr +='<tr><td>'+ v.taname+'</td><td>';
										attr +='<select name="attr['+ v.taid+']" id=""><option value="0">请选择</option>';
										$.each(v.tavalue,function(kk,vv){
											attr +='<option value="'+vv+'">'+vv+'</option>';
										})
										attr += '</select></td></tr>';
									}else{
										spec += '<tr><td>'+ v.taname+'</td><td>';
										spec += '<select name="spec['+ v.taid+'][guige][]" id=""><option value="0">请选择</option>';
										$.each(v.tavalue,function(kk,vv){
											spec += '<option value="'+vv+'">'+vv+'</option>';
										})
										spec += '</select></td><td>附加价格</td>';
										spec += '<td><input type="text" name="spec['+ v.taid+'][added][]"></td><td><button type="button" class="btn btn-primary btn-xs addspec">添加</button></td></tr>';
									}
								})
								attr +='</table>';
								spec += '</table>';
								$('#attr').html(attr);
								$("#spec").html(spec);
							},'json')

						})
					})
				</script>
<!--				点击添加按钮添加一个规格-->
				<script>
					$(function(){
						$('#spec').delegate('.addspec','click',function(){
							//将父级tr复制一份
							var tr=$(this).parents('tr').clone();
							//找到添加按钮将其删除，换成删除按钮
							tr.find('.addspec').remove();
							var del='<button type="button" class="btn btn-danger btn-xs delspec">删除</button>';
							tr.find('td').eq(4).append(del);
							$(this).parents('tr').after(tr);
						})
						$('#spec').delegate('.delspec','click',function(){
							$(this).parents('tr').remove();
						})
					})
				</script>

				<div class="form-group">
					<label for="" class="col-sm-2 control-label">所属品牌</label>
					<div class="col-sm-9">
						<select class="js-example-basic-single form-control" name="bid">
							<option value="0">请选择品牌</option>
							<?php foreach ((array)$branddata as $k=>$v){?>
								<option value="<?php echo $v['bid']?>" <?php if($goodsdata['bid']==$v['bid']){?>
                selected
               <?php }?> ><?php echo $v['bname']?></option>
							<?php }?>
						</select>
					</div>
				</div>
				<div class="form-group">
					<label for="" class="col-sm-2 control-label">商品属性</label>
					<div class="col-sm-9" id="attr">
						<table class="table table-striped">
							<?php foreach ((array)$attrdata as $k=>$v){?>
								<tr>
									<td><?php echo $v['taname']?></td>
									<td>
										<select name="attr[<?php echo $v['taid'] ?>]" id="">
											<option value="0">请选择</option>
											<?php foreach ((array)$v['tavalue'] as $kk=>$vv){?>
												<option value="<?php echo $vv?>" <?php if(in_array($vv,$goodsattr)){ ?>selected<?php } ?> ><?php echo $vv?></option>
											<?php }?>
										</select>
									</td>
								</tr>
							<?php }?>
						</table>
					</div>
				</div>
				<div class="form-group">
					<label for="" class="col-sm-2 control-label">商品规格</label>
					<div class="col-sm-9" id="spec">
						<table class="table table-striped">
							<?php foreach ((array)$goodspec as $k=>$v){?>
								<tr>
									<td><?php echo $v['taname']?></td>
									<td>
										<select name="spec[<?php echo $v['taid'] ?>][guige][]" id="">
											<option value="0">请选择</option>
											<?php foreach ((array)$v['tavalue'] as $kk=>$vv){?>
												<option value="<?php echo $vv?>" <?php if($v['gavalue']==$vv){?>
                selected
               <?php }?> ><?php echo $vv?></option>
											<?php }?>
										</select>
									</td>
									<td>附加价格</td>
									<td>
										<input type="text" value="<?php echo $v['added']?>" name="spec[<?php echo $v['taid']?>][added][]">
									</td>
									<td>
										<button type="button" class="btn btn-danger btn-xs delspec">删除</button>
									</td>
								</tr>
<!--								为什么没有这句话添加按钮不出来-->

								<script>
									$(function(){
										/*tr:contains意思是找到所有内容为$v['taname']的tr元素,找到第一个tr的最后一个td,html()是替换的意思*/
										$('#spec').find("tr:contains('<?php echo $v['taname']?>')").eq(0).find('td:last').html('<button type="button" class="btn btn-primary btn-xs addspec" >添加</button>');
									})
								</script>

							<?php }?>
						</table>
					</div>
				</div>
				<div class="form-group">
					<label for="" class="col-sm-2 control-label">商品货号</label>
					<div class="col-sm-9">
						<input type="text" name="gnumber" value="<?php echo $goodsdata['gnumber']?>"  class="form-control" placeholder="">
					</div>
				</div>
				<div class="form-group">
					<label for="" class="col-sm-2 control-label">商品描述</label>
					<div class="col-sm-9">
						<input type="text" name="describe" value="<?php echo $goodsdata['describe']?>"  class="form-control" placeholder="">
					</div>
				</div>
				<div class="form-group">
					<label for="" class="col-sm-2 control-label">单位</label>
					<div class="col-sm-9">
						<input type="text" name="unit" value="<?php echo $goodsdata['unit']?>" class="form-control" placeholder="">
					</div>
				</div>
				<div class="form-group">
					<label for="" class="col-sm-2 control-label">市场价</label>
					<div class="col-sm-9">
						<input type="text" name="marketprice" value="<?php echo $goodsdata['marketprice']?>"  class="form-control" placeholder="">
					</div>
				</div>
				<div class="form-group">
					<label for="" class="col-sm-2 control-label">商城价</label>
					<div class="col-sm-9">
						<input type="text" name="shopprice" value="<?php echo $goodsdata['shopprice']?>"  class="form-control" placeholder="">
					</div>
				</div>
				<div class="form-group">
					<label for="" class="col-sm-2 control-label">总库存</label>
					<div class="col-sm-9">
						<input type="text" name="total" value="<?php echo $goodsdata['total']?>" class="form-control" placeholder="">
					</div>
				</div>
				<div class="form-group">
					<label for="" class="col-sm-2 control-label">列表图</label>
					<div class="col-sm-9">
						<div class="input-group">
							<input type="text" class="form-control" name="pic" readonly="" value="<?php echo $goodsdata['pic']?>">
							<div class="input-group-btn">
								<button onclick="upImage(this)" class="btn btn-default" type="button" >选择图片
								</button>
							</div>
						</div>
						<div class="input-group" style="margin-top:5px;">
							<img src="<?php echo $goodsdata['pic']?:'resource/images/nopic.jpg'?>" class="img-responsive img-thumbnail liebiaotu"
							     width="150">
							<em class="close" style="position:absolute; top: 0px; right: -14px;" title="删除这张图片" onclick="removeImg(this)">×</em>
						</div>
						<span class="help-block">建议大小(宽100高100)</span>
					</div>
				</div>
				<div class="form-group">
					<label for="" class="col-sm-2 control-label">商品图册</label>
					<div class="col-sm-9">
						<div class="input-group">
							<div class="input-group-btn">
								<button onclick="manyupImage(this)" class="btn btn-default" type="button">选择图片</button>
							</div>
						</div>
						<div class="input-group" id="box" style="margin-top:5px;">

							<?php foreach ((array)$small as $k=>$v){?>
								<div  style="position: relative;float: left;border: 1px solid #ddd;margin-right:10px;margin-bottom:10px;width: 168px;height: 168px;">
									<li style="float: left;list-style: none">
											<img src="<?php echo $v?>" class="img-responsive " width="150" height="150" width="168">

										<input type="hidden" name="logo[]" value="<?php echo $v?>">
									</li>
									<em onclick="removeManyImg(this)" class="close" style=position: absolute; right: 3px;top:0px; " title="删除这张图片" ">×</em>
								</div>
							<?php }?>

						</div>
						<span class="help-block">建议大小(宽100高100)</span>
					</div>
				</div>
				<div class="form-group">
					<label for="" class="col-sm-2 control-label">点击次数</label>
					<div class="col-sm-9">
						<input type="text" name="click" value="<?php echo $goodsdata['click']?>" class="form-control" placeholder="">
					</div>
				</div>

				<div class="form-group">
					<label class="col-sm-2 control-label">商品详情</label>
					<div class="col-sm-9">
						<textarea id="intro" name="intro" style="height:300px;width:100%;"><?php echo $goodsdata['intro']?></textarea>
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-2 control-label">售后服务</label>
					<div class="col-sm-9">
						<textarea id="service" name="service" style="height:300px;width:100%;"><?php echo $goodsdata['service']?></textarea>
					</div>
				</div>
			</div>
		</div>
		<input type="hidden" name="gid" value="<?php echo $gid?>">
		<input type="hidden" name="tid" value="<?php echo $goodsdata['tid']?>">
		<button class="btn btn-primary" type="submit">确定修改</button>
	<input type='hidden' name='__TOKEN__' value='802d645edc78e8efe5b732c027a95f34'/></form>


        </div>
    </div>
</div>
<div class="master-footer" style="margin-top: 150px">
    <a href="http://www.houdunwang.com">高端培训</a>
    <a href="http://www.hdphp.com">开源框架</a>
    <a href="http://bbs.houdunwang.com">后盾论坛</a>
    <br>
    Powered by hdphp v2.0 © 2016-2022 www.hdphp.com
</div>
</body>
</html>
<script>
    require(['bootstrap'],function($){})
</script>

<script>
	//上传
	function upImage(obj) {
		require(['util'], function (util) {
			util.image(function (images) {
				$("[name='pic']").val(images[0]);
				$(".liebiaotu").attr('src', images[0]);
			}, {})
		})
	}
//	异步删除图片
	function removeImg(obj) {
		var path=$("input:text[name=pic]").val();
		$(obj).prev('img').attr('src', 'resource/images/nopic.jpg');
		$(obj).parent().prev().find('input').val('');

		$.ajax({
			type:'post',
			url:"<?php echo u('goods.removeImg')?>",
			data:{path:path}
		})
	}
	//多图上传删除图片
	function removeManyImg(obj){
		$(obj).parent().remove();
	}
	//百度编辑器
	require(['util'], function (util) {
		util.ueditor('container', {}, function (editor) {
			//这是回调函数 editor是百度编辑器实例
		});
	})
</script>
<script>
	//上传图片
	function manyupImage(obj) {
		require(['util'], function (util) {
			options = {
				//上传多图
				multiple: true,
			};
			util.image(function (images) {
				$(images).each(function(k,v){
					var li = '<li style="float: left;list-style: none"> <img src="'+v+'" class="img-responsive img-thumbnail" width="150"><input type="hidden" name="logo[]" value="'+v+'"></li>';

					$(li).appendTo('#box');
				})
			}, options)
		});
	}
</script>
<script>
	util.ueditor('service', {hash:2,data:'hd'}, function (editor) {
		//这是回调函数 editor是百度编辑器实例
	});
	util.ueditor('intro', {hash:2,data:'hd'}, function (editor) {
		//这是回调函数 editor是百度编辑器实例
	});
</script>
<script>
	function goodsEdit()
	{
		var data=$('#form').serialize();
		$.post("<?php echo u('edit')?>",data,function(res){
			if(res.valid){
				util.message(res.message,"<?php echo u('index')?>",'success');
			}else{
				util.message(res.message,"",'error');
			}
		},'json')

		return false;
	}
</script>